import React from "react";
import { Navigate } from "react-router-dom";

// 懒加载组件
const Cart = React.lazy(() => import("../pages/Cart"));
const Classify = React.lazy(() => import("../pages/Classify"));
const Detail = React.lazy(() => import("../pages/Detail"));
const Home = React.lazy(() => import("../pages/Home"));
const Login = React.lazy(() => import("../pages/Login"));
const MainLayout = React.lazy(() => import("../pages/MainLayout"));
const My = React.lazy(() => import("../pages/My"));

// 导航栏路由
export const tabbarRoutes = [
  {
    path: "/home",
    meta: {
      title: "首页",
    },
    element: <Home />,
  },
  {
    path: "/classify",
    meta: {
      title: "分类",
    },
    element: <Classify />,
  },
  {
    path: "/cart",
    meta: {
      title: "购物车",
    },
    element: <Cart />,
  },
  {
    path: "/my",
    meta: {
      title: "我的",
    },
    element: <My />,
  },
];
// 路由配置
const routes = [
  {
    path: "/detail/:id",
    element: <Detail></Detail>,
  },
  {
    path: "/login",
    element: <Login></Login>,
  },
  {
    path: "/",
    element: <MainLayout></MainLayout>,
    children: [
      ...tabbarRoutes,
      {
        path: "/",
        element: <Navigate to="/home"></Navigate>,
      },
    ],
  },
];

export default routes;
